var express = require('express');
var router = express.Router();
const {getAllAdmin,getAllAdminCount,updateAdmin,delAdmin,addAdmin,getOneAdmin,login2} = require("../../service/admin/adminServe");

//获取所有管理员
router.get('/getAllAdmin', async function(req, res, next) {
    const getParams = req.query;
    res.send(await getAllAdmin(getParams));
});

//根据id获取用户信息
router.get('/getOneAdmin', async function(req, res, next) {
    const getParams = req.query;
    const users = await getOneAdmin(getParams);
    res.send(users[0]);
});

// //获取所有管理员总数
router.get('/getAllAdminCount', async function(req, res, next) {
    const num = await getAllAdminCount()
    res.send({num});
});

// // 登录
router.get('/login', async function (req, res, next) {
    const data = await login2(req.query);
    res.send(data)
});
//修改管理员
router.post('/updateAdmin', async function(req, res, next) {
    const postParams = req.body;
    const bool = await updateAdmin(postParams);
    res.send({success:bool});
});

//删除管理员
router.post('/delAdmin', async function(req, res, next) {
    const postParams = req.body;
    const bool = await delAdmin(postParams);
    res.send({success:bool});
});

//添加管理员
router.post('/addAdmin', async function(req, res, next) {
    const postParams = req.body;
    const bool = await addAdmin(postParams);
    res.send({success:bool});
});


module.exports = router;